package org.metasketch.simulator.resources;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ResourceBank {

	Map<String, ResourceBase> resourceBaseByIdentifier = new HashMap<String, ResourceBase>();

	List<Resource> resources = new ArrayList<Resource>();
	List<ResourceClass> resourceClasses = new ArrayList<ResourceClass>();

	Map<String, Object> attributes = new HashMap<String, Object>();

	public ResourceBase getByInitialIdentifier(String partialKey) {
		Set<String> keys = resourceBaseByIdentifier.keySet();
		for (String key : keys) {
			if (key.startsWith(partialKey))
				return resourceBaseByIdentifier.get(key);
		}

		return null;
	}

	public void compile() {
		resourceBaseByIdentifier.clear();
		for (Resource resource : resources) {
			resourceBaseByIdentifier.put(resource.getIdentifier(), resource);
		}

		for (ResourceClass resource : resourceClasses) {
			resourceBaseByIdentifier.put(resource.getIdentifier(), resource);
		}

	}

	public List<Resource> getResources() {
		return resources;
	}

	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}

	public List<ResourceClass> getResourceClasses() {
		return resourceClasses;
	}

	public void setResourceClasses(List<ResourceClass> resourceClasses) {
		this.resourceClasses = resourceClasses;
	}

	public Map<String, ResourceBase> getResourceBaseByIdentifier() {
		return resourceBaseByIdentifier;
	}

	public void setResourceBaseByIdentifier(
			Map<String, ResourceBase> resourceBaseByIdentifier) {
		this.resourceBaseByIdentifier = resourceBaseByIdentifier;
	}

	public Map<String, Object> getAttributes() {
		return attributes;
	}

	public void setAttributes(Map<String, Object> attributes) {
		this.attributes = attributes;
	}

	// Map<Long, ResourceBase> resources = new HashMap<Long, ResourceBase>();
	//
	// public Map<Long, ResourceBase> getResources() {
	// return resources;
	// }
	//
	// public void setResources(Map<Long, ResourceBase> resources) {
	// this.resources = resources;
	// }

}
